package com.azhon.basic.storage.sqlite;

import org.litepal.crud.DataSupport;
import java.util.List;
import androidx.annotation.NonNull;

/**
 * 数据库角标操作类
 */
public class BadgeNumTableOperation {
    
    @NonNull
    private static BadgeNumTableOperation op = new BadgeNumTableOperation();
    
    private BadgeNumTableOperation(){}
    
    @NonNull
    public static BadgeNumTableOperation getOperation(){
        return op;
    }
    
    /**
     * 存储数据库角标
     * @param timeMillis
     * @return
     */
    public boolean saveBadgeNumTable(String timeMillis){
        BadgeNumTable lBadgeNumTable = new BadgeNumTable(timeMillis);
        return lBadgeNumTable.save();
    }
    
    /**
     * 删除某条数据库角标
     * @param timeMillis
     */
    public void deleteBadgeNumTable(String timeMillis){
        UseHistory.deleteAll(BadgeNumTable.class, "timeMillis = ?", timeMillis);
    }
    
    /**
     * 删除数据库角标
     */
    public void deleteBadgeNumTables(){
        UseHistory.deleteAll(BadgeNumTable.class);
    }
    
    /**
     * 查询数据库角标数量
     */
    public int searchNumberOfBadgeNum(){
        List<BadgeNumTable> lBadgeNumTableList = DataSupport.findAll(BadgeNumTable.class);
        if (!lBadgeNumTableList.isEmpty()){
            return lBadgeNumTableList.size();
        }else{
            return 0;
        }
    }
    
}
